package java6681.lesson12;

import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author Junichiro
 * @description 数值流的使用
 * @date 2021-05-29 18:58
 **/

public class SimpleStream6681 {
    public static void main(String[] args) {
        Random r = new Random();
        int sum = Stream.generate(() -> r.nextInt(61))
                .limit(40).distinct().filter(x -> IntStream.range(2, (int) Math.sqrt(x) + 1)
                        .filter(t -> x % t == 0).count() == 0).sorted().mapToInt(n -> {
                    System.out.print(n + " ");
                    return n;
                }).sum();
        System.out.print(" = " + sum);

    }
}


//        long sum = r.ints(0, 61).limit(40)
//                .filter(x -> IntStream.range(2, (int) Math.sqrt(x) + 1)
//                        .filter(t -> x % t == 0).count() == 0).mapToLong(n -> {
//                    System.out.print(n + " ");
//                    return n;
//                }).sum();
//        System.out.print(" = " + sum);